package com.tiancheng.trade.payment.enums;

import com.tiancheng.trade.commom.core.enums.BaseEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * @Author: likailun
 * @Description: 二维码交易中台枚举
 * @Date: create in 2021/9/13 4:32 下午
 */
@Getter
@AllArgsConstructor
public enum QrTradeStatusEnum implements BaseEnum<Integer> {
    INIT(0,"初始流水"),
    C2B_CONSUMER_ADDN(5,"附加处理"),
    C2B_CONSUMER(31,"消费交易"),
    C2B_CONSUMER_RIGHTING(32,"消费冲正交易"),
    C2B_CONSUMER_REVOKE(33,"消费撤销交易"),
    C2B_CONSUMER_REFUND(34,"退货交易");


    private Integer code;
    private String desc;

    public static String getDesc(Integer code) {
        Optional<QrTradeStatusEnum> found = Arrays.stream(QrTradeStatusEnum.values()).filter(c -> c.code.equals(code)).findFirst();
        if (found.isPresent()) {
            return found.get().getDesc();
        }
        return "";
    }

    public static QrTradeStatusEnum getByCode(Integer code){
        Optional<QrTradeStatusEnum> found = Arrays.stream(QrTradeStatusEnum.values()).filter(c -> c.code.equals(code)).findFirst();
        return found.orElse(null);
    }

}
